import { ClassNames } from '@mantine/core';
import classNames from 'classnames';

export const mergeClassNames =
  (...args: (ClassNames<any> | undefined)[]) =>
  (theme: any, props: any, ctx: any) => {
    return args
      .map((arg) => (typeof arg === 'function' ? arg(theme, props, ctx) : arg))
      .reduce((o, cls) => {
        Object.keys(cls || {}).forEach((name) => {
          o[name] = classNames(o[name], cls![name]);
        });
        return o;
      }, {} as any);
  };
